<?php



$debug=0;
$dbhost = "localhost";
$dbuser = "fossilplot";
$dbpass = "fossilplot";
$dbname = "fossilplot";
//Connect to MySQL Server
mysql_connect($dbhost, $dbuser, $dbpass);
//Select Database
mysql_select_db($dbname) or die(mysql_error());
// Retrieve data from Query String
//$F = $_GET['F'];
$arrGen = $_POST['arrGen'];
$arrCart = $_POST['arrCart'];



//$arrSel = $_GET['arrSel'];

//echo "array is :".$arrSel."<br>";

//echo "hello F".$F."<br>";
if($debug){
echo "hello selected Gen ".$arrGen."<br>";
echo "hello Cart ".str_replace('*','+',$arrCart)."<br>";
}
//$exploded_cart = explode(',', str_replace('*','+',$arrCart));

//$exploded_gen = explode(',', str_replace('*','+',$arrGen));

$exploded_cart = explode(',', $arrCart);

$exploded_gen = explode(',', $arrGen);

//$exploded_cart = explode(',', $arrCart);

//$exploded_gen = explode(',', $arrGen);
if($debug){
echo "exploded gen 3 is ".$exploded_gen[0]."<br>";
echo "size of selected gen is ".sizeof($exploded_gen)."<br>";
}
ob_flush(); flush();
if ($arrGen == null && $exploded_cart[0]=="No Items Selected"){
	
		echo "<select name=\"G[]\" multiple size=\"63\" style=\"WIDTH: 290px\">";
		echo "<option>"."No Items Selected"."</option>";
		echo "</select>";
	
	
}
else{ //$arrGen is not null
//echo "cart is $exploded_cart[0]";

echo "<div id=\"select_container\" style=\"overflow-x:scroll; width:290px; overflow: -moz-scrollbars-horizontal;\" >";
echo "<select name=\"G[]\" multiple size=\"63\">";

foreach($exploded_cart as $tmp_cart){
if($tmp_cart != "No Items Selected"){
echo "<option>".$tmp_cart."</option>";
}

}

foreach($exploded_gen as $tmp_gen) {
	$track=0;
	if($exploded_cart[0]!="No Items Selected"){ //if old cart only has "No Items Selected", no need to check duplicated genera
		
		foreach($exploded_cart as $tmp_cart){
			if(strpos($tmp_cart, $tmp_gen) !== false){
				 $track=1;
			}
		}
		
	}
	if($track==1) {next;}
	else{
		$result = mysql_query("select phylum_name, class_name, order_name,fad_date,lad_date from genus where genus_name='$tmp_gen'");
		while ($row = mysql_fetch_array($result)) {
			//$a[$i][0]=$vclass[$i];
			//$a[$i][1]= $row{'id'};
			//echo "<script language=\"javascript\" type=\"text/javascript\">alert(\"hello\")</script>";
			//$temp =$row{'phylum_id'};
			//$temc=$row{'class_id'};
			//$temo=$row{'order_id'};
			//$p= mysql_query("select phylum_name from fossilplot.phylum where id='$temp'");
			//$c= mysql_query("select class_name from fossilplot.class where id='$temc'");
			//$o= mysql_query("select order_name from fossilplot.order where id='$temo'");
			//while($rowp=mysql_fetch_array($p)){
				//$temp=$rowp{'phylum_name'};
			//}
			//while($rowc=mysql_fetch_array($c)){
				//$temc=$rowc{'class_name'};
			//}
			//while($rowo=mysql_fetch_array($o)){
				//$temo=$rowo{'order_name'};
			//}
			//echo "<option>".$row{'genus_name'}."; ".$row{'phylum_name'}."; ".$row{'class_name'}.";".$row{'order_name'}."; ".$row{'fad_date'}."; ".$row{'lad_date'}."</option>";
			echo "<option>".$tmp_gen."; ".$row{'phylum_name'}."; ".$row{'class_name'}.";".$row{'order_name'}."; ".$row{'fad_date'}."; ".$row{'lad_date'}."</option>";

		
		} //end of while
	} //end of else

}




echo "</select>";

echo "</div>";
} //end of else ($arrGen is not null)


?>